package com.example.passwordmanager;

import android.content.Context;
import androidx.biometric.BiometricPrompt;
import androidx.fragment.app.FragmentActivity;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;

public class BiometricAuth {
    private final Context context;
    private final BiometricPrompt.AuthenticationCallback callback;

    public BiometricAuth(Context context, BiometricPrompt.AuthenticationCallback callback) {
        this.context = context;
        this.callback = callback;
    }

    public void authenticate() {
        Executor executor = Executors.newSingleThreadExecutor();
        BiometricPrompt biometricPrompt = new BiometricPrompt(
                (FragmentActivity) context,
                executor,
                callback
        );

        BiometricPrompt.PromptInfo promptInfo = new BiometricPrompt.PromptInfo.Builder()
                .setTitle(context.getString(R.string.biometric_auth_title))
                .setSubtitle(context.getString(R.string.biometric_auth_subtitle))
                .setNegativeButtonText(context.getString(R.string.cancel))
                .setConfirmationRequired(false)
                .build();

        biometricPrompt.authenticate(promptInfo);
    }
}